package com.wwtech.epp.ui.adapter.work;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.TaskDetail;
import com.wwtech.epp.utils.WorkUtil;

import java.util.List;

import static com.wwtech.epp.R.id.status;

/**
 * Created by hu on 2017/10/4.
 */

public class TaskListAdapter extends BaseQuickAdapter<TaskDetail, BaseViewHolder> {
    public int categry = 0;       //类型，0 为我发布的。  1为 分配我的
    public TaskListAdapter(@Nullable List<TaskDetail> data) {
        super(R.layout.item_task_list, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, TaskDetail listBean) {
        baseViewHolder.setText(R.id.title, listBean.getJobTitle())
                .setText(R.id.content, listBean.getJobContent())
                .setText(R.id.creat_name, listBean.getNickName())
                .setText(R.id.end_time, listBean.getDeadline().substring(0, 11));
        TextView state = baseViewHolder.getView(status);
        if (listBean.getFiles().size() == 0) {
            baseViewHolder.setVisible(R.id.iv_attachment, false);
        } else {
            baseViewHolder.setVisible(R.id.iv_attachment, true);
        }
        baseViewHolder.setText(R.id.categery, categry == 0? "负责人：" : "创建人：");
        if (WorkUtil.isUnValuableTask(listBean.getDeadline()) == -1 || listBean.getJobState() == 2) {
            switch (listBean.getJobState()) {
                case 0:
                    state.setText("新任务");
                    state.setTextColor(mContext.getResources().getColor(R.color.color_new_task));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.new_task_bg));
                    break;
                case 1:
                    state.setText("进行中");
                    state.setTextColor(mContext.getResources().getColor(R.color.main_color));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.ing_task_bg));
                    break;
                case 2:
                    state.setText("已完成");
                    state.setTextColor(mContext.getResources().getColor(R.color.color_finish_task));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.finish_task_bg));
                    break;
            }
        } else {
            state.setText("过期" + WorkUtil.isUnValuableTask(listBean.getDeadline()) + "天");
            state.setTextColor(mContext.getResources().getColor(R.color.color_f51818));
            state.setBackground(null);
        }
    }
}
